/* Punity Library: Basic Use
 * Fredrik Bridell 2009
 *
 * This is a first example of how to use the Punity Library for 
 * unit testing from withing the Processing IDE.
 * The steps needed are
 * 1. Import the library
 * 2. Create a new Tester
 * 3. Perform some tests
 *      tester.assertEquals(expected, actual, message) 
 * 4. When you feel like it, show the results (tester.showSummary()) or 
 *    print them out (tester.printResults())
 *
 * Note how I use the tester.isTesting() and setTesting(true/false) methods 
 * to toggle what the Processing sketch is doing.
 *
 * Oh, when you run this you'll need to press some keys for something to happen:
 * t = test
 * p = print (to the console)
 * c = continue
 */

import com.bridell.punity.*;
Tester tester;
PFont font;

void setup() {
  size(600, 600);
  tester = new Tester(this);
}

void draw() {
  if (tester.isTesting()){
  	tester.showSummary();
  } else {
    // here you can just do whatever your sketch is supposed to do normally
    for(int i=0; i<50; i++){
      fill(random(0, 255), 128, 128);
      rect(random(0, width), random(0, height), random(5, 10), random(5, 10));
    }
  }
}

/* There is nothing magical about the name of this method.
 * You'll need to invoke it manually.
 */
void doTest(){
	tester.reset();
	tester.setTesting(true);
	 
	int foo = 47+11;
  	tester.assertEquals(1, 1, "one is one");
  	tester.assertEquals(58, foo, "doing some math");
}

void keyPressed(){
	if (key == 't'){ // TEST
		doTest();
	}
	
	if (key == 'p'){ // PRINT
		tester.printResults();
	}
	
	if (key == 'c'){ // CONTINUE
                background(128);
		tester.setTesting(false);
	}
}
